<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .todo li {
            padding: 10px 0;
        }

        .finish li {
            color: #999;
            text-decoration: line-through;
        }

        .btn {
            margin-left: 10px;
            padding: 2px 8px;
        }
    </style>
</head>
<body>
    <div id="app">
        <input type="text" v-model="things">
        <button @click="save">保存</button>
        <p>待完成</p>
        <ul class="todo">
            <li v-for="(item, index) in todoList">
                <span>{{item}}</span>
                <button class="btn" @click="del(index)">del</button>
            </li>
        </ul>
        <hr>
        <p>已搞定</p>
        <ul class="finish" id="done">
            <li v-for="item in doneList">{{item}}</li>
        </ul>
    </div>
    <script src="./vue.js"></script>
    <script>
        var Todo = {
            data() {
                return {
                    things: '',
                    todoList: [],
                    doneList: []
                }
            },
            methods: {
                save() {
                    // 判断 不为空
                    if(this.things) {
                        this.todoList.push(this.things);
                        this.things = '';
                    }
                },
                del(index) {
                    this.doneList.push(this.todoList[index]);
                    this.todoList.splice(index, 1);
                }
            }
        }
        Vue.createApp(Todo).mount('#app');
    </script>
</body>
</html>